/*
 *  Copyright (C) 2025 ameise <ameise.wang@gmail.com> - All Rights Reserved
 *
 *  This file is part of e3utils.
 *
 *  e3utils is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  e3utils is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with e3utils. If not, see <https://www.gnu.org/licenses/>.
 */

package rand

import (
	"math/rand/v2"

	"gitee.com/ameise84/e3utils/rand/internal/pcg"
)

func NewRand(s1 uint64, s2 uint64) *E3Rand {
	r := &E3Rand{
		pcg: pcg.NewPCG(s1, s2),
	}
	r.Rand = rand.New(r.pcg)
	return r
}

type E3Rand struct {
	*rand.Rand
	pcg *pcg.PCG
}

func (ts *E3Rand) Seed(s1, s2 uint64) {
	ts.pcg.Seed(s1, s2)
}

func (ts *E3Rand) MarshalPCG() ([]byte, error) {
	return ts.pcg.MarshalBinary()
}

func (ts *E3Rand) UnMarshalPCG(bs []byte) error {
	return ts.pcg.UnmarshalBinary(bs)
}

func (ts *E3Rand) R1K() int {
	return ts.IntN(1000)
}

func (ts *E3Rand) R10K() int {
	return ts.IntN(10000)
}

func (ts *E3Rand) R100K() int {
	return ts.IntN(100000)
}
